<script type="text/javascript">
    _this.onLoad(function () {
        if (Program.data_question != "" && Program.data_question != null) {

            if (_this.storage.get("mute") == "stop") {
                $("#page_indexstatistic .Mute").addClass("stop");
            }
            $("#page_indexstatistic .Mute").off("tap");
            $("#page_indexstatistic .Mute").on("tap", function (e) {
                if (!$(this).hasClass('stop')) {
                    if (intro != null)
                        intro.pause();
                    
                    if (background != null)
                        background.pause();
                    
                    $(".Mute").addClass('stop');
                    _this.storage.set("mute", "stop");
                } else {
                    background.play();
                    $(".Mute").removeClass('stop');
                    _this.storage.set("mute", "play");
                }
                e.preventDefault();
                return false;
            });
            Statistic.init = function () {

                var count = 0;
                var ItemAnswer = '', OtherAnswer = '';

                $.each(Program.data_question.choice, function (index, item) {
                    count++;
                    ItemAnswer += '<a class="answer-statistics"><span>' + count + '</span>' + item[0].stripslashes() + '</a>';
                });
                if (Program.other_opinion == 1) {
                    count++;
                    OtherAnswer = '<a id="answerid_' + count + '" data-id="' + count + '"><span>' + count + '</span>Ý kiến khác</a>';
                }

                $(".Des_Answer").html(ItemAnswer + OtherAnswer);

                initCharts("", count);
            };

            Statistic.runSocket = function () {

                socket.emit('get-analytic', Program.id_question, Program.id_tvshow);

                socket.on('response-get-analytic', function (data_) {
                    var ids_show = Program.id_tvshow;
                    var ids_show = ids_show ? ids_show : 0;
                    var id_tvshow_ = data_.id_tvshow;
                    if (id_tvshow_ == ids_show) {
                        numAnalytics = 0;

                        var data = data_.analytics;

                        var length_ = data.length;
                        var _data = [];
                        var count_rs = 0;
                        for (var iz = 1; iz < length_; iz++) {
                            var npt = (data[iz] * 100) / data_.data2;
                            var n = parseFloat(npt);
                            var pt = format_number(n, 1);
                            _data.push(pt);
                        }
                        updateChart(_data);
                    }
                });

                socket.on('receiveAnalytic', function (newdata) {
					
                    if (newdata.id_tvshow == Program.id_tvshow) {
                        if (newdata.user_id == User.id) {
                            Statistic.changeStatus('done');
                        }

                        numAnalytics = 0;
                        var data = newdata.vote;
                        var length_ = data.length;
                        var _data = [];
                        for (iz = 1; iz < length_; iz++) {
                            var npt = (data[iz] * 100) / newdata.tanalyticsRoom;
                            var n = parseFloat(npt);
                            var pt = format_number(n, 1);
                            _data.push(pt);
                        }
                        updateChart(_data);

                    }
                });
            };

            Template.get("page_indexstatistic", function () {
                _this.selector(".Header_text").UI_AddClassHover("hover");
                _this.selector(".Header_text").off("tap");
                _this.selector(".Header_text").on("tap", function () {
                    _this.redirect("index/index");
                });
                Statistic.init();
                new Popup().close();
                Statistic.runSocket();
            });
        }
    });
</script>
<div class="UI_Body FadeIn">
    <div id="Statistic">
        <div class="Inner">
            <div class="Statistic_Header">Thống kê kết quả trả lời</div>
            <div class="Statistic_Chart">

            </div>
            <div class="Statistic_Description">
                <div class="Des_Answer">
                </div>
            </div>
        </div>
    </div>
</div>
<div class="UI_Footer">
    <a href="#" class="Mute"></a>
    <p>Sản phẩm của <img src="public/images/vtv-digital.png" alt=""/></p>
</div>